package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JDBCDemo11 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil1.getConnection();){//获取连接 自动关闭连接
            connection.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);//设置隔离级别 默认是可重复读
            connection.setAutoCommit(false);//设置手动提交事务
            String sql = "insert into user(username,password,nickname,age)"+"values(?,?,?,?)";//插入数据
            PreparedStatement ps = connection.prepareStatement(sql);//预编译sql语句
            ps.setString(1,"张三");
            ps.setString(2,"123456");
            ps.setString(3,"三儿");
            ps.setInt(4,18);
            int num = ps.executeUpdate();
            System.out.println(num>0?"注册成功":"注册失败");
            connection.commit();

        }catch (SQLException e){
            e.printStackTrace();
        }
    }
}
